//
//  NSMutableArray+Runtime.m
//  fuyoukache
//
//  Created by 曹运 on 16/11/14.
//  Copyright © 2016年 foryou. All rights reserved.
//

#import "NSMutableArray+Runtime.h"

@implementation NSMutableArray (Runtime)
+ (void)load
{
    SEL safeSel_m   = @selector(safeObjectAtIndex_m:);
    SEL unsafeSel_m = @selector(objectAtIndex:);
    
    Class class_m = NSClassFromString(@"__NSArrayM");
    
    Method safeMethod_m   = class_getInstanceMethod(class_m, safeSel_m);
    Method unsafeMethod_m = class_getInstanceMethod(class_m, unsafeSel_m);
    
    method_exchangeImplementations(safeMethod_m, unsafeMethod_m);
}
- (id)safeObjectAtIndex_m:(NSUInteger)index
{
    if (self == nil) {
        return nil;
    }
    if (self.count == 0) {
        return nil;
    }
    if (index > (self.count - 1)) {
        //        NSAssert(NO, @"beyond the boundary");
        return nil;
    } else {
        return [self safeObjectAtIndex_m:index];
    }
}
@end
